package it.test.java.decoratord.pay.decorator;

import it.test.java.decoratord.pay.domain.Order;
import it.test.java.decoratord.pay.domain.SupportPromotions;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Copyright 纳新智能科技有限公司
 * @Author Liky
 * @Date 2023/9/27
 */
public class CouponDecorator extends CountDecorator{

    private SupportPromotions supportPromotions;

    public CouponDecorator(IBaseCount baseCount, SupportPromotions supportPromotions) {
        super(baseCount);
        this.supportPromotions = supportPromotions;
    }

    @Override
    public BigDecimal getMoney(Order order) {
        super.getMoney(order);
        return caluConuponMoney(order);
    }

    private BigDecimal caluConuponMoney(Order order){
        System.out.println("-----------------------使用优惠券-----------------------");
        BigDecimal coupon = supportPromotions.getUserCoupon().getCoupon();
        BigDecimal thresholdAmount = supportPromotions.getUserCoupon().getThresholdAmount();
        System.out.println("优惠券使用门槛：" + thresholdAmount);
        System.out.println("优惠券金额：" + coupon);

        if(order.getPayMoney().compareTo(thresholdAmount) >= 0){
            order.setPayMoney(order.getPayMoney().subtract(coupon).setScale(2, BigDecimal.ROUND_HALF_UP));
        }
        System.out.println("优惠券后商品价格：" + order.getPayMoney());
        return order.getPayMoney();
    }
}
